package org.zjx.log;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * FileLogHandler将日志输出到文件。
 */
public class FileLogHandler implements LogHandler {
    private String logFilePath;

    public FileLogHandler(String logFilePath) {
        this.logFilePath = logFilePath;
    }

    @Override
    public void handleLog(LogLevel level, String message) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(logFilePath, true))) {
            writer.write(message);
            writer.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
